<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2018/10/25
 * Time: 10:22
 */

namespace app\qgroup\validate;


use app\common\Enum\CommonEnum;
use app\common\util\ReturnMsgUtil;
use app\qgroup\model\QqCodeMapping;
use think\Validate;

class ConfigValidate extends Validate
{
    use ReturnMsgUtil;
    protected  $rule = [
        'qq'=>'require|validateQQInfo'
        ,'token'=>'require'
        ,'qgroup'=>'array|require'
        ,'masterQQ'=>'require'
        ,'group'=>'require'
        ,'qqs'=>'array|require'
    ];

    protected $message = [
        'qq.require'=>'非法访问,CODE:QQR'
        ,'token.require'=>'非法访问,CODE:TR'
        ,'qgroup.require'=>'非法访问,CODE:QR'
        ,'qgroup.array'=>'非法访问,CODE:QA'
        ,'masterQQ.require'=>'非法访问,CODE:MR'
        ,'group.require'=>'非法访问,CODE:GR'
        ,'qqs.require'=>'非法访问,CODE:QSR'
        ,'qqs.array'=>'非法访问,CODE:QSA'
    ];

    protected $scene = [
        'getCode'=>['qq']
        ,'putCode'=>['qq','code']
        ,'queryCode'=>['qq']
        ,'update'=>['masterQQ','qq']
        ,'synchronizationGroup'=>['qgroup','qq']
        ,'updateGroup'=>['qq','masterQQ','group']
        ,'init'=>['qq.require','group']
        ,'updateGroupMemberInfo'=>['group','qqs']
    ];

    /**
     * 验证QQ号状态
     * @param $value
     * @return bool|string
     * @throws \think\exception\DbException
     */
    public function validateQQInfo($value)
    {
        $qcm = QqCodeMapping::get(['qq'=>$value]);
        if (!$qcm){
            return '此QQ暂未注册';
        }
        if (!$qcm->status){
            return '此QQ未获取注册码';
        }
        if ($qcm->activation_state == CommonEnum::COMMON_INVALID){
            return '此QQ未填写注册码';
        }
        return true;
    }
}